﻿using ViewMaker.Core.Controls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using ViewMaker.Core;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using ViewMaker.Core.Tests.Controls;

namespace ViewMaker.Core.Tests
{
    [TestClass()]
    public class RadioButtonListViewControlTest
    {
        [TestMethod()]
        public void 標準的なRadioButtonListのXAML生成()
        {
            var target = new RadioButtonListViewControl { Item = new ViewLayoutItem { Name = "rb001", Caption = "ラジオボタンリスト", BindPath = "currentValue" } };
            target.ItemsSource = "dataSource";
            var parent = TestHelper.CreateTestParent();
            parent.AppendChild(target.CreateXaml(parent)[1]);
            var actual = (ListBox)TestHelper.GetFrameworkElement<ContentControl>(parent).Content;
            Assert.AreEqual("rb001", actual.Name);
            Assert.AreEqual("currentValue", actual.GetBindingExpression(ListBox.SelectedItemProperty).ParentBinding.Path.Path);
            Assert.AreEqual("dataSource", actual.GetBindingExpression(ListBox.ItemsSourceProperty).ParentBinding.Path.Path);
            Assert.AreEqual(BindingMode.TwoWay, actual.GetBindingExpression(ListBox.SelectedItemProperty).ParentBinding.Mode);
        }

        [TestMethod()]
        public void 横方向に配置したRadioButtonListのXAML生成()
        {
            var target = new RadioButtonListViewControl { Item = new ViewLayoutItem { Name = "rb001", Caption = "ラジオボタンリスト", BindPath = "currentValue" } };
            target.ItemsSource = "dataSource";
            target.ItemWidth = 100;
            target.Orientation = LayoutOrientation.Horizontal;
            var parent = TestHelper.CreateTestParent();
            parent.AppendChild(target.CreateXaml(parent)[1]);
            var xaml = parent;
            var actual = (ListBox)TestHelper.GetFrameworkElement<ContentControl>(parent).Content;
            Assert.AreEqual("rb001", actual.Name);
            Assert.AreEqual("currentValue", actual.GetBindingExpression(ListBox.SelectedItemProperty).ParentBinding.Path.Path);
            Assert.AreEqual("dataSource", actual.GetBindingExpression(ListBox.ItemsSourceProperty).ParentBinding.Path.Path);
            Assert.AreEqual(BindingMode.TwoWay, actual.GetBindingExpression(ListBox.SelectedItemProperty).ParentBinding.Mode);
        }

        [TestMethod()]
        public void RadioButtonListViewControlの編集画面が表示可能()
        {
            var target = new RadioButtonListViewControl { Item = new ViewLayoutItem { Name = "rb001", Caption = "ラジオボタンリスト", BindPath = "currentValue" } };
            target.ItemsSource = "dataSource";
            var baml = ViewUtil.BuildContent(target);
            Assert.IsNotNull(baml);
        }

    }
}
